package com.example.composestudy.part7

import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Preview(showBackground = true)
@Composable
fun AnimateAsSateTest() {
    var isSmall by remember { mutableStateOf(true) }
    val size by animateDpAsState(if (isSmall) 40.dp else 100.dp)
    Column(modifier = Modifier.padding(16.dp)) {
        Button(onClick = {
            isSmall = !isSmall
        }) {
            Text(text = "改变大小")
        }
        Box(modifier = Modifier.size(size).background(Color.Blue))
    }
}
